package com.atguigu.gmall.product.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.mapper.BaseCategoryViewMapper;
import com.atguigu.gmall.product.service.ManageSerivce;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/product/inner")
public class ProductApiController {
    @Autowired
    private ManageSerivce manageSerivce;
    @Autowired
    private BaseCategoryViewMapper baseCategoryViewMapper;
    /**
     * 根据skuId获取sku信息
     * FeignClient:  api/product/inner/getSkuInfo/{skuId}
     */
    @ApiOperation("根据skuId获取sku信息")
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId")Long skuId){
        return manageSerivce.getSkuInfo(skuId);
    }

    /**
     * 通过三级分类id查询分类信息
     * @param category3Id
     * @return
     */
    @ApiOperation("通过三级分类id查询分类信息")
    @GetMapping("getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id")Long category3Id){
        return manageSerivce.getBaseCategoryViewByCategory3Id(category3Id);
    }

    /**
     * 获取sku最新价格
     * @param skuId
     * @return
     */
    @ApiOperation("获取sku最新价格")
    @GetMapping("getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId")Long skuId){
        return manageSerivce.getSkuPrice(skuId);
    }

    /**
     * 根据spuId skuId 查询销售属性集合
     * @param skuId
     * @param spuId
     * @return
     */
    @ApiOperation("根据spuId skuId 查询销售属性集合")
    @GetMapping("getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> selectSpuSaleAttrListCheckBySku(@PathVariable("skuId") Long skuId,
                                                             @PathVariable("spuId") Long spuId){
        return manageSerivce.selectSpuSaleAttrListCheckBySku(skuId,spuId);
    }

    /**
     * 根据spuId 查询map 集合属性
     * @param spuId
     * @return
     */
    @ApiOperation("根据spuId 查询map 集合属性")
    @GetMapping("getSkuValueIdMap/{spuId}")
    public Map getSkuValueIdMap(@PathVariable("spuId")Long spuId){
        return manageSerivce.getSkuValueIdsMap(spuId);
    }

    /**
     * 获取全部分类信息
     * @return
     */
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        return Result.ok(manageSerivce.getBestCategoryList());
    }

    /**
     * 通过品牌Id 集合来查询数据
     * @param tmId
     * @return
     */
    @GetMapping("inner/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable("tmId")Long tmId){
        return manageSerivce.getTrademarkByTmId(tmId);
    }

    /**
     * 通过skuId 集合来查询数据
     * @param skuId
     * @return
     */
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId){
        return manageSerivce.getAttrList(skuId);
    }

}
